/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.rbh.risk.converter;

import com.rbh.risk.entity.SubCause;
import com.rbh.risk.service.SubCauseService;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.ManagedProperty;
import javax.faces.bean.RequestScoped;
import javax.faces.component.UIComponent;
import javax.faces.context.FacesContext;
import javax.faces.convert.Converter;
import javax.faces.convert.FacesConverter;

/**
 *
 * @author M
 */
@ManagedBean(name = "subCauseConvert")
@RequestScoped
@FacesConverter(forClass = SubCause.class)
public class SubCauseConverter implements Converter {

    @ManagedProperty("#{subCauseService}")
    private SubCauseService subCauseService;

    @Override
    public Object getAsObject(FacesContext context, UIComponent component, String value) {
        SubCause result = null;
        try {
            result = subCauseService.getById(Integer.parseInt(value));
        } catch (Exception ex) {
        }
        return result;
    }

    @Override
    public String getAsString(FacesContext context, UIComponent component, Object value) {
        String result = "";
        try {
            SubCause subCause = (SubCause) value;
            result = subCause.getSubCauseId()+"";
        } catch (Exception ex) {
        }
        return result;
    }

    public SubCauseService getSubCauseService() {
        return subCauseService;
    }

    public void setSubCauseService(SubCauseService subCauseService) {
        this.subCauseService = subCauseService;
    }
    
}